﻿using System;
using System.Diagnostics;

namespace mForum.Infrastructure.NHibernate
{
    using mForum.Core.Common;
    using mForum.Core.Infrastructure;

    public class UnitOfWork : IUnitOfWork
    {
        private IDatabaseFactory _dbFactory;
        private DatabaseContext _dbContext;

        public UnitOfWork(IDatabaseFactory dbFactory)
        {
            Check.Argument.IsNotNull(dbFactory, "databaseFactory");

            _dbFactory = dbFactory;
        }

        protected DatabaseContext DatabaseContext
        {
            [DebuggerStepThrough]
            get
            {
                return _dbContext ?? (_dbContext = _dbFactory.Get());
            }
        }

        public void Commit()
        {
            DatabaseContext.Commit();
        }
    }
}
